package com.zhenwei.zscm.controller;

import com.zhenwei.zscm.common.annotations.MethodName;
import com.zhenwei.zscm.common.base.RestResult;
import com.zhenwei.zscm.service.FileService;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/api/file")
@MethodName("文件上传下载管理接口")
public class FileController {
    private FileService fileService;

    @PostMapping("/upload")
    @MethodName("文件上传接口")
    public RestResult uploadFiles(@RequestParam("files") List<MultipartFile> files) {
        return fileService.uploadFiles(files);
    }

    @GetMapping("/download")
    @MethodName("文件下载接口")
    public ResponseEntity<byte[]> downloadFile(@RequestParam String fileId) {
       return fileService.download(fileId);
    }

    @PostMapping("/info")
    @MethodName("获取文件信息")
    public RestResult getFileInfo(@RequestBody @NotEmpty(message = "文件ID不能为空") List<String> fileIds) {
        return fileService.getFileInfo(fileIds);
    }
}
